<template>
  <!--勘察附件start -->
  <el-dialog
    v-dialogDrag
    :title="dialogTitle"
    :close-on-click-modal="false"
    :visible.sync="dialogVisible"
    class="dialogStyleMiddle"
    :before-close="cancel"
  >
    <el-form
      ref="addForm"
      :rules="rules"
      class="dialog-form"
      :model="formData"
      label-width="80px"
    >
      <el-form-item label="物探报告" prop="experimentList">
        <FileUplode
          ref="fileUplode"
          :edit-file-list="experimentList"
          :status="status"
          @getFileList="getOutline"
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <DialogFooter />
    </div>
  </el-dialog>
  <!--勘察附件end -->
</template>

<script>
// 页面接口
import { updateProject, getAttachment } from '@/api/projectManage/project'
// 上传文件
import FileUplode from '@/components/Upload/FileUplode'
// dialog-footer
import DialogFooter from '@/components/Common/Btns/DialogFooter/index'
export default {
  components: {
    FileUplode,
    DialogFooter
  },
  data() {
    return {
      status: '',
      experimentList: [],
      /* 新增 start*/
      dialogTitle: '', // 弹层标题
      dialogVisible: false, // 弹层是否显示
      formData: { // 新增数据
        id: '', // 项目id
        experimentList: ''
      },
      rules: {
        experimentList: [{ required: true, message: '物探报告不能为空', trigger: 'blur' }]
      }
      /* 新增 end*/
    }
  },
  methods: {
    /* 新增/编辑弹层 start*/
    // 新增/编辑
    handleAdd(id) {
      this.dialogTitle = '物探报告'
      this.dialogVisible = true
      this.emptyAddForm()
      this.formData.id = id
      this.getDetailById(id)
    },
    // 查询物探报告的详情
    async getDetailById(id) {
      const { data } = await getAttachment(id)
      if (data) {
        this.formData = { ...data }
        if (data.experimentList && data.experimentList.length > 0) {
          this.experimentList = data.experimentList
        }
      }
    },
    // 取消按钮
    cancel() {
      this.dialogVisible = false
    },
    // 提交按钮
    submitForm() {
      this.$refs['addForm'].validate(async valid => {
        if (valid) {
          const { id, experimentList, experiment } = this.formData
          await updateProject({ id, experimentList, experiment })
          this.msgSuccess('物探报告通过')
          this.dialogVisible = false
        }
      })
    },
    /* 新增弹层 end*/
    getOutline(fileList, deleteFileIds) {
      this.formData.experimentList = fileList
    },
    // 表单重置
    emptyAddForm() {
      this.resetForm('addForm')
      this.formData.id = ''
      this.experimentList = []
    }
  }

}
</script>

<style>

</style>
